#include <pthread.h>
#include <string.h>
#include <unistd.h>
#include <iostream>


using std::cout;
using std::endl;

//子线程执行流的入口
//子线程本质上就是一个函数
void * start_routine(void * arg)
{
    cout << "sub thread is running." << endl;
    cout << "sub thread id is " << pthread_self() << endl;
    //while(1);
    sleep(5);
    return NULL;
}


int main()
{
    pthread_t pthid;
    int ret = pthread_create(&pthid, NULL, start_routine, NULL);
    if(ret != 0) {
        fprintf(stderr, "pthread_create:%s\n", strerror(ret));
        return EXIT_FAILURE;
    }

    cout << "main thread is running, sub thread id:" << pthid << endl;
    cout << "main thread id:" << pthread_self() << endl;
    while(1);

    return 0;
}

